package Theard;

import java.awt.Color;
import java.awt.Font;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class HinhHoc extends JFrame implements ActionListener{
	int tam;
	JLabel td= new JLabel();	
	JLabel canh1= new JLabel();
	JLabel canh2= new JLabel();	
	JLabel kq= new JLabel();
	JLabel cv= new JLabel();
	JLabel dt= new JLabel();
	
	JTextField khungcanh1= new JTextField();
	JTextField khungcanh2= new JTextField();
	JTextField khungdt= new JTextField();
	JTextField khungcv= new JTextField();
	
	JRadioButton hcn= new JRadioButton();
	JRadioButton ht= new JRadioButton();
	JRadioButton hv= new JRadioButton();
	
	JButton thuchien=new JButton();
	JButton tieptuc=new JButton();
	JButton thoat=new JButton();
	public HinhHoc(){
		
		//super("Chu vi & diện tích");
		
		setSize(550,550);
		thuchien.addActionListener(this);
		tieptuc.addActionListener(this);
		thoat.addActionListener(this);
		
		hv.addActionListener(this);
		hcn.addActionListener(this);
		ht.addActionListener(this);
		
		
		//tiêu đề
		this.getContentPane().setLayout(null);
		td.setForeground(Color.BLUE);
		td.setFont(new Font(getName(),Font.BOLD,20));
		td.setBounds(new Rectangle(100,25, 350,50));
		td.setText("BẢNG TÍNH CHU VI & DIỆN TÍCH");
		this.getContentPane().add(td);
		
		//canh 1
		canh1.setBounds(new Rectangle(50,125, 100, 50));
		this.getContentPane().add(canh1);
		khungcanh1.setBounds(new Rectangle(150,100,100,50));
		this.getContentPane().add(khungcanh1);
		//canh2
		canh2.setBounds(new Rectangle(50,200, 100, 50));
		this.getContentPane().add(canh2);
		khungcanh2.setBounds(new Rectangle(150,175,100,50));
		this.getContentPane().add(khungcanh2);
		//button HCN
		hcn.setBounds(new Rectangle(350,150,200,50));
		hcn.setText("Hình chữ nhật");
		hcn.setFont(new Font(getName(),Font.BOLD,15));
		this.getContentPane().add(hcn);
		//button HT
		ht.setBounds(new Rectangle(350,225,200,50));
		ht.setText("Hình Tròn");
		ht.setFont(new Font(getName(),Font.BOLD,15));
		this.getContentPane().add(ht);
		//hinh vuông
		hv.setBounds(new Rectangle(350,300,200,50));
		hv.setText("Hình Vuông");
		hv.setFont(new Font(getName(),Font.BOLD,15));
		this.getContentPane().add(hv);
		//ket qua
		kq.setBounds(new Rectangle(150,225, 100, 50));		
		kq.setText("Kết quả: ");
		kq.setFont(new Font(getName(),Font.BOLD,15));
		this.getContentPane().add(kq);
		//dien tich
		dt.setBounds(new Rectangle(50,275, 100, 50));
		this.getContentPane().add(dt);
		dt.setText("Diện tích:");
		khungdt.setBounds(new Rectangle(150,275,100,50));
		this.getContentPane().add(khungdt);
		//chu vi
		cv.setBounds(new Rectangle(50,350, 100, 50));
		this.getContentPane().add(cv);
		cv.setText("Chu vi:");
		khungcv.setBounds(new Rectangle(150,350,100,50));
		this.getContentPane().add(khungcv);
		//tinh
		thuchien.setBounds(new Rectangle(50,425, 100, 50));
		thuchien.setText("Tính");
		thuchien.setBackground(Color.LIGHT_GRAY);
		thuchien.setOpaque(true);
		this.getContentPane().add(thuchien);		
		//tieptuc
		tieptuc.setBounds(new Rectangle(200,425, 100, 50));
		tieptuc.setText("Xóa");
		tieptuc.setBackground(Color.LIGHT_GRAY);
		tieptuc.setOpaque(true);		
		this.getContentPane().add(tieptuc);	
		//thoat
		thoat.setBounds(new Rectangle(350,425, 100, 50));
		thoat.setText("thoát");
		thoat.setBackground(Color.LIGHT_GRAY);
		thoat.setOpaque(true);
		this.getContentPane().add(thoat);	
		ButtonGroup g1= new ButtonGroup();
		g1.add(hcn);g1.add(ht);g1.add(hv);
		
		khungcanh1.setVisible(false);
		khungcanh2.setVisible(false);
		canh1.setVisible(false);
		canh2.setVisible(false);
	}
	
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		HinhHoc hh=new HinhHoc();
		hh.setVisible(true);
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		
		if(e.getSource()==hv || e.getSource()==hcn || e.getSource()==ht){
			if(hv.isSelected() == true || ht.isSelected() == true){
				khungcanh1.setVisible(true);
				khungcanh2.setVisible(false);
				canh1.setVisible(true);
				canh2.setVisible(false);
				
				if(hv.isSelected() == true){
					canh1.setText("Cạnh a:");
				}
				else {
					canh1.setText("Bán kính r:");
				}
			}
			else if(hcn.isSelected() == true){
				khungcanh1.setVisible(true);
				khungcanh2.setVisible(true);
				canh1.setText("Chieu dai:");
				canh2.setText("Chieu rong:");
				canh1.setVisible(true);
				canh2.setVisible(true);
			}
		}
		
		if(e.getSource() == thuchien){
			
		}
		
		if(e.getSource() == tieptuc){
			
		}
		
		if(e.getSource() == thoat){
			
		}
		
	}	

}
